<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<div><p onmouseup="mytest(event)">只是一段<b>ssss</b>文本其余的还有很多的文字</p></div>
<script>

    function mytest(e){
        // console.log(window.getSelection(), e);
        let s = window.getSelection();
        console.log('获取到选中的文字：\n', s.baseNode.data.substring(s.anchorOffset, s.focusOffset))
    }

</script>
</body>
</html>